package net.bolue.web.util;

import net.bolue.sysmng.tblbean.ColInfo;
import net.bolue.sysmng.tblbean.RefDicRes;
import net.bolue.sysmng.tblbean.RepCnd;
import net.bolue.web.entry.FormDataOption;
import net.bolue.web.entry.FormElemTag;

public class TagUtil {

	/**
	 * 表列信息生成表单标签
	 * @param colInfo
	 * @return
	 */
	public static FormElemTag colToField(ColInfo colInfo){
		if(colInfo==null){
			return null;
		}
		FormElemTag formElemTag = new FormElemTag();
		formElemTag.setTagName(colInfo.getColName());
		formElemTag.setTagTitle(colInfo.getColDesc());
		Integer tagType = colInfo.getTagType();
		if(tagType==null||tagType==1){
			tagType = getTagTypeByDic(colInfo.getDicKind(),colInfo.getDicSubSys(),colInfo.getDicGrpid());
		}
		if(tagType==null||tagType==1){
			tagType = getTagType(colInfo.getTagType(),colInfo.getJType(),colInfo.getColSize());
		}
		formElemTag.setTagType(tagType);
		Integer tagLen = colInfo.getDispLen();
		if(tagLen>colInfo.getColSize()){
			tagLen = colInfo.getColSize();
		}
		formElemTag.setTagLen(tagLen);
		formElemTag.setNullAble(colInfo.getIsNullAble());
		formElemTag.setDicKind(colInfo.getDicKind());
		formElemTag.setDicSubSys(colInfo.getDicSubSys());
		formElemTag.setDicGrpid(colInfo.getDicGrpid()+"");
		formElemTag.setValDicCol(colInfo.getValDicCol());
		formElemTag.setPostFixTag(colInfo.getPostFixTag());
		
		return formElemTag;
	}
	
	public static FormElemTag cndToField(RepCnd repCnd){
		if(repCnd==null){
			return null;
		}
		FormElemTag formElemTag = new FormElemTag();
		formElemTag.setTagName(repCnd.getCndName());
		formElemTag.setTagTitle(repCnd.getDispName());
		formElemTag.setTagType(repCnd.getTagType());
		formElemTag.setDicKind(repCnd.getDicKind());
		formElemTag.setDicGrpid(repCnd.getDicGrpId()+"");
		formElemTag.setNullAble(repCnd.getIsNullAble());
		
		return formElemTag;
	}
	
	public static FormDataOption refDicToOption(RefDicRes refDicRes){
		if(refDicRes==null){
			return null;
		}
		FormDataOption formDataOption = new FormDataOption();
		return formDataOption;
	}
	
	public static Integer getTagType(Integer tageType,Integer jtype,Integer columnSize){
		if(tageType!=1){
			return tageType;
		}
		tageType = 7;
		if(jtype==3&&columnSize>200){
			tageType = 8;
		}
		return tageType;
	}
	
	public static Integer getTagTypeByDic(Integer dicKind,String subSys,Integer dicGrpId){
		Integer tageType = null;
		if(dicKind==1||dicKind==2){
			tageType = 2;
		}else if(dicKind==4){
			tageType = 2;
		}
		return tageType;
	}
}
